1 00:00:00,510 --> 00:00:04,720 Hello and welcome to this select show in this show. 2 00:00:04,770 --> 00:00:15,150 We will be creating a couple of functions to respond to the key and key down events in the previous 3 00:00:15,150 --> 00:00:15,740 lectures. 4 00:00:15,740 --> 00:00:25,770 We created event listeners to listen out for when key up when the key down events occur. 5 00:00:27,830 --> 00:00:32,800 To save time I have already created a piece of code. 6 00:00:32,810 --> 00:00:40,880 This is a function here that will control the key down events so whenever there is a when they read 7 00:00:40,880 --> 00:00:43,840 the key is down on the keyboard. 8 00:00:44,150 --> 00:00:50,700 This function is what will be fired up to respond to that. 9 00:00:50,720 --> 00:00:53,310 So let me just run through the function here. 10 00:00:53,310 --> 00:00:55,430 I started with a keyword function. 11 00:00:55,430 --> 00:01:01,290 That's what you need to type to create a function followed by the name of the function. 12 00:01:01,290 --> 00:01:11,680 It's always good to name your functions as closely as possible to the activity you want them to perform. 13 00:01:11,810 --> 00:01:15,060 So this function here is called Key down. 14 00:01:15,070 --> 00:01:22,970 HANDLER it takes in one parameter which is represented by this E P variable here. 15 00:01:22,990 --> 00:01:33,230 It takes an event as the parameter so if the key on the cursor on the keyboard is press that it is down 16 00:01:33,420 --> 00:01:41,380 that means it is pressed and that is an event so it will store the information in this e variable. 17 00:01:41,480 --> 00:01:45,620 So what will then happen once that information is stored. 18 00:01:45,740 --> 00:01:53,630 Implemented in IF statement so what this IF statement is saying is that the perimeter is where you specify 19 00:01:53,630 --> 00:01:54,150 be. 20 00:01:54,260 --> 00:01:58,650 If statement is saying if this event which is this E. 21 00:01:58,670 --> 00:02:04,900 Here is the key called is e wars to 39. 22 00:02:05,210 --> 00:02:12,490 So the key chord 39 represents when the right cursor is pressed. 23 00:02:12,710 --> 00:02:19,310 So what this code is saying is if that she is press press down is 39. 24 00:02:19,320 --> 00:02:28,550 That means you are holding on or you press in down the right cursor So that equals to true else. 25 00:02:28,660 --> 00:02:38,150 If you are not press in down the right key or right cursor if you are press in if the key you are pressin 26 00:02:38,240 --> 00:02:43,130 which means if e doors key could equal so 37. 27 00:02:43,130 --> 00:02:52,690 If the key is 37 instead that means you are actually presson on the left cursor or left key. 28 00:02:52,730 --> 00:02:56,820 In that case that value is also true. 29 00:02:57,770 --> 00:03:06,420 So what this piece of code is saying is that any time we press on any of these keys the key number 39 30 00:03:06,440 --> 00:03:13,330 which represents the right cursor or key number 37 which represent the left cursor. 31 00:03:13,430 --> 00:03:20,670 So any time either of those keys are pressed that means the function. 32 00:03:20,810 --> 00:03:27,240 This function here will be fired up and that information will be stored inside. 33 00:03:27,300 --> 00:03:34,220 This is variable so any time you press any of those key variable here stores that information and fires 34 00:03:34,220 --> 00:03:36,890 up this function. 35 00:03:36,920 --> 00:03:46,100 Next we are going to create another variable that will counteract this function. 36 00:03:46,100 --> 00:03:50,360 So this foreign churn will kick off when these conditions are true. 37 00:03:50,360 --> 00:03:53,450 That means when either of these keys are pressed. 38 00:03:53,450 --> 00:03:57,030 So what happens when those keys are unlocked pressed. 39 00:03:57,080 --> 00:04:01,510 So when the keys are released that means the keys will be up. 40 00:04:01,520 --> 00:04:10,070 So are we going to create another function called key up handler and Paulson is going to take one parameter 41 00:04:10,100 --> 00:04:17,730 which is the event variable that will store the information that the key is naturally up. 42 00:04:17,750 --> 00:04:27,330 In that case the variables the variables will be false because if he's not pressed them is up. 43 00:04:29,000 --> 00:04:35,020 All right so this piece of code here is the function for the key up Handler. 44 00:04:35,210 --> 00:04:41,560 It takes him warm perimeter which is the whole of the event. 45 00:04:42,560 --> 00:04:48,220 The perimeter is represented by this guy here is also known as event. 46 00:04:48,240 --> 00:04:56,450 So if we when we know that from the first could hear this fence function when the keys are pressed that 47 00:04:56,520 --> 00:05:00,060 means the key is down and the value is true. 48 00:05:00,350 --> 00:05:02,030 This phone chant is the opposite. 49 00:05:02,060 --> 00:05:08,450 So when the keys are released and they are not pressed the information is variable. 50 00:05:08,510 --> 00:05:12,590 Tell this function that the keys are up they are not being pressed. 51 00:05:12,590 --> 00:05:16,970 In that case the value is equal to force. 52 00:05:17,060 --> 00:05:22,270 The moment we pressed the key and the key goes down it becomes the value changes. 53 00:05:22,310 --> 00:05:23,030 True. 54 00:05:23,120 --> 00:05:26,020 And this fell's function here will be fired up. 55 00:05:26,120 --> 00:05:34,430 So when the keys are down it's Phong shell will kick off and when the key are released that means the 56 00:05:34,430 --> 00:05:37,830 unlock Press function will kick off. 57 00:05:37,880 --> 00:05:44,940 So this too will handle when the key is up and when the key is down. 58 00:05:45,770 --> 00:05:54,170 So for a quick summary of what the functions do the first function will be fired off when the key on 59 00:05:54,170 --> 00:05:56,690 the keyboard is pressed down. 60 00:05:56,690 --> 00:06:05,090 So when the right key or the left key is pressed down the key down function will be fired up because 61 00:06:05,090 --> 00:06:11,990 that information is stored in the variable that would trigger the function to kick-off. 62 00:06:12,080 --> 00:06:17,700 The second option is when the key is not pressed. 63 00:06:17,750 --> 00:06:28,490 That means the key handler will be fired up and that function will kick off bullet parameters but function 64 00:06:28,490 --> 00:06:32,970 stakes in the value of e which is the event variable. 65 00:06:33,530 --> 00:06:42,600 So when the keys are pressed now be values set true and when the key is not pressed when they're up. 66 00:06:42,740 --> 00:06:46,930 The variable is set to force. 67 00:06:47,150 --> 00:06:51,450 Thank you so much for your time and watch it in the next lecture. 68 00:06:51,500 --> 00:07:00,990 We are going to be creating some logic that we can use to control the movement of the pad. 69 00:07:01,460 --> 00:07:02,810 Thank you so much. 70 00:07:02,810 --> 00:07:03,750 Bye for now.